<!--23-DOM-getElementsByName.html-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>getElementsByName</title>
    <script>
        function clickAll() {
            var elementsByName = document.getElementsByName("languages");
            for (var i = 0; i < elementsByName.length; i++) {
                elementsByName[i].checked = true;
            }
        }

        function clickNon() {
            var elementsByName = document.getElementsByName("languages");
            for (var i = 0; i < elementsByName.length; i++) {
                elementsByName[i].checked = false;
            }
        }
        
        function checkReverse() {
            var elementsByName = document.getElementsByName("languages");
            for (let i = 0; i < elementsByName.length; i++) {
                elementsByName[i].checked = !elementsByName[i].checked;
            }
        }
        
    </script>
</head>
<body>
    选择你喜欢的语言：
    <input type="checkbox" name="languages"/>Java
    <input type="checkbox" name="languages"/>C++
    <input type="checkbox" name="languages"/>Python
    <br>
    <button onclick="clickAll()">全选</button>
    <button onclick="clickNon()">全不选</button>
    <button onclick="checkReverse()">反选</button>
</body>
</html>